package com.gd.data.platform.controller.api;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gd.data.platform.dto.ApiResponse;
import com.gd.data.platform.service.ext.DataQualityService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 数据质量API控制器
 * 提供数据质量监控接口
 * 
 * @author gd-data-platform
 * @since 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/quality")
@Api(tags = "数据质量API")
public class DataQualityController {

    @Autowired
    private DataQualityService dataQualityService;

    /**
     * 获取数据质量报告
     */
    @GetMapping("/report")
    @ApiOperation("获取数据质量报告")
    public ApiResponse<Map<String, Object>> getDataQualityReport() {
        try {
            Map<String, Object> report = dataQualityService.getDataQualityReport();
            return ApiResponse.success(report);
        } catch (Exception e) {
            log.error("获取数据质量报告失败", e);
            return ApiResponse.error("获取数据质量报告失败：" + e.getMessage());
        }
    }

    /**
     * 手动执行数据质量检查
     */
    @PostMapping("/check")
    @ApiOperation("手动执行数据质量检查")
    public ApiResponse<String> checkDataQuality() {
        try {
            dataQualityService.checkDataQuality();
            return ApiResponse.success("数据质量检查完成");
        } catch (Exception e) {
            log.error("执行数据质量检查失败", e);
            return ApiResponse.error("执行数据质量检查失败：" + e.getMessage());
        }
    }
}
